package com.example.xwadmin.api.ai;

import com.alibaba.dashscope.aigc.generation.Generation;
import com.alibaba.dashscope.aigc.generation.GenerationResult;
import com.alibaba.dashscope.aigc.generation.models.QwenParam;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;

public class AiJudge {
    public static int callWithMessage(String content) throws NoApiKeyException, ApiException, InputRequiredException {
        Generation gen = new Generation();
        QwenParam params = QwenParam.builder().model(Generation.Models.QWEN_TURBO)
                 .apiKey(System.getenv("DASHSCOPE_API_KEY")) //也可以手工导入环境变量的值
                .prompt("角色:你是一个ai微博审核助手，任务：每隔一段时间会自动筛选待审核的微博，状态(wb_state)为2," +
                        "当你发现一个微博在讨论违法法律、宣扬反动言论或者辱骂他人的时候，你就发出-1来表示该微博需要被封禁，" +
                        "无需封禁只输出1，如果无法判定则输出3，例如:有人说：cnm张三。你就应当给于封禁,但你只需要输出1，无需封禁只输出0" +
                        "举例完毕。用户录入:"+content)
                .seed(0)
                .topP(0.8)
                .resultFormat("message")
                .enableSearch(false)
                .maxTokens(300)
                .temperature((float)0.85)
                .repetitionPenalty((float)1.0)
                .build();

        GenerationResult result = gen.call(params);
        System.out.println(result);
        return result.getOutput().getChoices().get(0).getMessage().getContent().equals("1")?1:0;
    }
}
